<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/salesReport.do?action=bbbReport" />

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>
<%@ page import="com.scalar.chiptrack.commons.Constants" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.GregorianCalendar" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>
<%
    String userTypeChiptrac     = Constants.USER_TYPE_CHIPTRAC + "";
    //try {
%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>

<script>
var dateElement = "";
function openCalendar(dateValue)
{
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.moveTo(550,180);
    newWindow.focus();
}
function assignDate(passedValue)
{
   dateElement.value=passedValue;
   window.focus();
}

function validateFromAndToDates()
{
    var form = document.salesReportForm;
    errMsg = '';

    var pa	= document.getElementById("errors");

    if(chkDate(form.fromDate.value,'From-Date','Y') == false)
    {
        pa.innerHTML = errMsg;
        form.fromDate.focus();
        return false;
    }

    if(chkDate(form.toDate.value,'To-Date','Y') == false)
    {
        pa.innerHTML = errMsg;
        form.toDate.focus();
        return false;
    }

    if(form.fromDate.value!='' && form.toDate.value!='')
    {
        if (!validateDateOut(formatDateAsMMDDYYYY(form.fromDate.value),formatDateAsMMDDYYYY(form.toDate.value)))
        {
            pa.innerHTML = "To Date cannot be less than From Date";
            form.toDate.focus();
            return false;
        }
    }

    return true;
}

function dateRange( fileType )
{
    var pa	= document.getElementById("errors");
    var form = document.salesReportForm;

    var success;
    success = true;
    success = validateFromAndToDates();
    if(success == false)
    {
       return false;
    }

    var partNumberObj =form.productIds;
    var processstepId = "";
    var count = 0;
    for( var i = 0; i < partNumberObj.length; i++ )
    {
        if( partNumberObj.options[i].selected )
        {
            count++;
            if ( processstepId != '' )
            {
                processstepId = processstepId + "," + partNumberObj.options[i].value;
            }
            else
            {
                processstepId = partNumberObj.options[i].value;
                if( partNumberObj.options[i].value == '0' )
                {
                    break;
                }
            }
        }
    }
    if ( processstepId == '')
    {
        processstepId = "0";
    }
    if( count > 10)
    {
        pa.innerHTML = "<li>Please select upto 10 Products only";
        return false;
    }
    else
    {
        form.productIds.value = processstepId;
    }

    if( fileType == 1 )
    {
        form.action ='<%=chipTracContext%>/salesReport.do?action=bbbReportXls';

        form.submit();
    }
}

function initLoad()
{
    var form = document.salesReportForm;
    <%!
      String fromDate = null;
      String toDate = null;
    %>
    <%

        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        Calendar calendar = Calendar.getInstance();
        GregorianCalendar gc = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
        gc.add(GregorianCalendar.YEAR, -1);
        Date d = gc.getTime();
        fromDate = sdf.format(d);

        SimpleDateFormat sdf1 = new SimpleDateFormat("MM/dd/yyyy");
        Calendar calendar1 = Calendar.getInstance();
        GregorianCalendar gc1 = new GregorianCalendar(calendar1.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
        gc1.add(GregorianCalendar.DATE, 1);
        Date d1 = gc1.getTime();
        toDate = sdf1.format(d1);
    %>
   form.fromDate.value = "<%=fromDate%>";
    form.toDate.value = "<%=toDate%>";
}

</script>


<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" onload="initLoad();">

<html:form name="salesReportForm" method="post" type="com.scalar.chiptrack.sales.forms.SalesReportForm" action="/salesReport.do?action=bbbReport">

<!-- Top Header Start-->
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/header.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/includes/extHeader.jsp" %>
    </logic:notEqual>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
<!-- Side Navigation start -->
<%--<%@ include file="/jsp/sales/sales_report_menu.jsp" %>--%>
    <logic:equal value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/sales/sales_report_menu.jsp" %>
    </logic:equal>
    <logic:notEqual value="<%=userTypeChiptrac%>" name="user" property="userType" scope="session">
        <%@ include file="/jsp/sales/external_reports_menu.jsp" %>
    </logic:notEqual>
<!-- end of the side navigations -->
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->

<center><span class="NArialW">BBB Reports&nbsp;&nbsp;&nbsp;&nbsp;</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
  <table border="0" width="90%" align=center cellspacing="4" cellpadding="2">
    <tr><td colspan=6 align="left" class='NArialL'><b><font face="Verdana" size="-5" align="center" color="#ff0000" id="errors"></font></b></td></tr>
    <tr><td colspan=6><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
    <tr>
        <td width="5%" valign= "top">&nbsp;</td>
        <td width="15%" valign= "top" class="NArialL">Customer :</td>
        <td width="20%" valign= "top" class="NArialL" >
            <nested:select property="customerId" styleClass="txfield" style= "width:190px">
            <html:options collection="customerSelectList" property="value" labelProperty="label"/>
            </nested:select>
        </td>
        <td width="5%">&nbsp;</td>
        <td width="15%" valign= "top" nowrap="true">
            <font class="NArialL"><bean:message key="label.mfgPartNumber" /> :</font>
        </td>
        <td width="20%" class="NArialL">
        <nested:select property="productIds" styleClass="txfield" style= "width:190px" multiple="true">
            <html:option value="0">All Products</html:option>
            <html:options collection="fgLabelValuebeanList" property="value" labelProperty="label"/>
            </nested:select>
        </td>
    </tr>
    <tr >
        <td width="5%" valign= "top">&nbsp;</td>
        <td width="20%"><font class="NArialL">Region :</font></td>
        <td width="20%" class="NArialL">
            <nested:select property="region" styleClass="txfield" style="width:170px" >
                <html:option value="0">All Regions</html:option>
                <html:options collection="regionList" property="value" labelProperty="label"/>
            </nested:select>
        </td>
        <td width="5%">&nbsp;</td>
        <td width="15%" class="NArialL">Regional Rep :</td>
        <td width="20%" class="NArialL">
        <nested:select property="regionRep" styleClass="txfield" style="width:170px" >
                <html:option value="0">All Regional Reps</html:option>
                <html:options collection="repOfficeList" property="value" labelProperty="label"/>
            </nested:select>
        </td>
    </tr>
    <tr>
        <td width="5%">&nbsp;</td>
        <td width="20%" nowrap><font class="NArialL"><bean:message key="label.sales.endCustomer"/> :</font></td>
        <td width="20%" class="NArialL">
            <nested:select property="endCustomer" styleClass="txfield" style= "width:170px">
                <html:option value="0">All <bean:message key="label.sales.endCustomer"/>s</html:option>
                <html:options collection="endCustomerList" property="value" labelProperty="label"/>

                </nested:select>
        </td>
        <td width="5%">&nbsp;</td>
        <td width="15%"><font class="NArialL">Sales Person :</font></td>
        <td width="20%"><font class="NArialL">
            <nested:select property="salesPerson" styleClass="txfield" style= "width:170px" >
                <html:option value="0">All Sales Persons</html:option>
                <html:options collection="salesPersonList" property="value" labelProperty="label"/>
                </nested:select>
            </font>
        </td>
    </tr>
    <tr>
        <td width="5%">&nbsp;</td>
        <td width="20%" class="NArialL"><bean:message key="label.sales.endUser"/> :</td>
        <td width="20%" class="NArialL">
        <nested:select property="endUser" styleClass="txfield" style= "width:170px" >
            <html:option value="0">All <bean:message key="label.sales.endUser"/>s</html:option>
            <html:options collection="endUserList" property="value" labelProperty="label"/>
        </nested:select>

        </td>
        <td width="5%">&nbsp;&nbsp;</td>
        <td width="15%" class="NArialL">Category :</td>
        <td width="20%" class="NArialL">
            <nested:select property="orderType" styleClass="txfield" style= "width:170px" >
                <html:option value="1">Regular</html:option>
                <html:option value="0">Sample</html:option>
                <html:option value="2">Consignment</html:option>
            </nested:select>
    </tr>

    <tr>
        <td width="5%">&nbsp;</td>
        <TD width="15%" class="NArialL" valign = 'top'>From Date<font color=red>*</font> :</TD>
        <TD width="20%" class="NArialL" valign = 'top'>
            <nested:text property="fromDate" size="12" styleClass="txfield"/>
            <a href="javascript:openCalendar(document.salesReportForm.fromDate)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18>
            </a>
        </TD>
        <td width="5%">&nbsp;&nbsp;</td>
        <TD width="15%" class="NArialL" valign = 'top'>To Date<font color=red>*</font> :</TD>
        <TD width="20%" class="NArialL" valign = 'top'>
            <nested:text property="toDate" size="12" styleClass="txfield"/>
            <a href="javascript:openCalendar(document.salesReportForm.toDate)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18>
            </a>
        </TD>
    </tr>

    <tr>
        <td colspan=5 align="center">&nbsp;</td>
        <td colspan=1 align="center">
        <a class="NArialL" href="javascript:dateRange(1)" onMouseOver="window.status='Click here to Export to Excel';return true" onMouseOut="window.status='';return true" title='Click here to Export to Excel' >Export to Excel</a>
    </td>
    </tr>

    <tr>
      <td colspan=6 align=center><input type="image" onClick="javascript:return dateRange(1);" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Report';return true"onmouseout="window.status='';return true"title="Click here to Generate Report"/>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="javascript:document.salesReportForm.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border='0' onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
    </tr>

  </table>

<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</html:form>
</BODY>
</HTML>
<%--<% } catch(Exception e){e.printStackTrace();} %>--%>
